<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>vfd-cloud - 分享链接</title>
    <!-- Custom fonts for this template-->
    <link th:href="@{/asserts/vendor/fontawesome-free/css/all.min.css}" rel="stylesheet" type="text/css">
    <link
            href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
            rel="stylesheet">

    <!-- Custom styles for this template-->
    <link th:href="@{/asserts/css/sb-admin-2.min.css}" rel="stylesheet">

    <style type="text/css">
        table{
            width:70%;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);/* 阴影 */
            border-collapse:collapse;/* 取消表格边框 */
            letter-spacing:1px;/* 文字缩进 */
        }
        table,th,tr,td {
            border-bottom: 1px solid #dedede; /* 表格横线 */
            padding: 29px;
            text-align: center;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>

</head>
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">
            <!-- Topbar -->
            <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                <!-- Sidebar Toggle (Topbar) -->
                <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                    <i class="fa fa-bars"></i>
                </button>
                <!-- Topbar Navbar -->
                <ul class="navbar-nav ml-auto">
                    <!-- Nav Item - Search Dropdown (Visible Only XS) -->
                    <li class="nav-item dropdown no-arrow d-sm-none">
                        <a class="nav-link dropdown-toggle" href="#" id="searchDropdown" role="button"
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <!-- Dropdown - Messages -->
                        <div class="dropdown-menu dropdown-menu-right p-3 shadow animated--grow-in"
                             aria-labelledby="searchDropdown">
                            <form class="form-inline mr-auto w-100 navbar-search">
                                <div class="input-group">
                                    <input type="text" class="form-control bg-light border-0 small"
                                           placeholder="Search for..." aria-label="Search"
                                           aria-describedby="basic-addon2">
                                    <div class="input-group-append">
                                        <button class="btn btn-primary" type="button">
                                            <i class="fas fa-search fa-sm"></i>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </li>

                    <!-- Nav Item - User Information -->
                    <li class="nav-item dropdown no-arrow">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <!--用户名-->
                            <span id="curr_user_name" class="mr-2 d-none d-lg-inline text-gray-600 small" th:text="${userName}"></span>
                            <img class="img-profile rounded-circle"
                                 src="/asserts/img/undraw_profile.svg">
                        </a>
                        <!-- Dropdown - User Information -->
                        <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
                             aria-labelledby="userDropdown">
                            <a class="dropdown-item" href="#" data-toggle="modal" data-target="#tipModal">
                                <i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
                                Profile
                            </a>
                            <a class="dropdown-item" href="#" data-toggle="modal" data-target="#tipModal">
                                <i class="fas fa-cogs fa-sm fa-fw mr-2 text-gray-400"></i>
                                Settings
                            </a>
                            <a class="dropdown-item" href="#" data-toggle="modal" data-target="#tipModal">
                                <i class="fas fa-list fa-sm fa-fw mr-2 text-gray-400"></i>
                                Activity Log
                            </a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
                                <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
                                退出
                            </a>
                        </div>
                    </li>
                </ul>
            </nav>
            <!-- End of Topbar -->

            <!-- Begin Page Content -->
            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="d-sm-flex align-items-center justify-content-between mb-4">
<!--                    <h3 class="h3 mb-0 text-gray-800"><p th:text="'文件分享者： '+ ${ownerName}"></p></h3>-->
                    <a href="javascript:void(0);" class="btn btn-danger btn-icon-split btn-sm" data-toggle="modal" data-target="#deleteAllModal">
                                        <span class="icon text-white-50">
                                            <i class="fas fa-trash-alt"></i>
                                        </span>
                        <span class="text">全部取消分享</span>
                    </a>
                </div>
            </div>

            <!--导航栏-->
            <div class="card shadow mb-4">
                <div class="card-body card mb-4 py-3 border-left-primary">
                    <div class="table-responsive">
                        <table class="table" id="dataTable" width="100%" cellspacing="0">
                            <thead>
                            <tr>
                                <th></th>
                                <th>文档名</th>
                                <th>链接</th>
                                <th>提取码</th>
                                <th>取消分享</th>
                                <th>有效期</th>
                            </tr>
                            </thead>
                            <tfoot>
                            <tr>
                                <th></th>
                                <th>文档名</th>
                                <th>链接</th>
                                <th>提取码</th>
                                <th>取消分享</th>
                                <th>有效期</th>
                            </tr>
                            </tfoot>
                            <tbody id="dir_tbody">
                                <tr th:each="iter, iterStat:${share}" th:id="'tr' + ${iterStat.index}">
                                    <td>
                                        <span th:if="${iter.getType()==0}" class="icon">
                                                <i style="color: lightskyblue" class="fas fa-folder fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==1}" class="icon">
                                                <i style="color: cornflowerblue" class="fas fa-file-alt fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==2}" class="icon">
                                                <i style="color: #09cb09" class="fas fa-image fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==3}" class="icon">
                                                <i style="color: blueviolet" class="fas fa-video fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==4}" class="icon">
                                                <i style="color: deeppink" class="fas fa-music fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==5}" class="icon">
                                                <i style="color: #069706" class="fas fa-file-code fa-2x"></i>
                                            </span>
                                        <span th:if="${iter.getType()==6}" class="icon">
                                                <i style="color: gray" class="fas fa-file fa-2x"></i>
                                            </span>
                                    </td>
                                    <td><span class="h5 m-0 text-dark" th:text="${iter.getName()}"></span></td>
                                    <td>
                                        <form class="user">
                                            <div class="form-group">
                                                <input readonly="readonly" type="text" class="form-control form-control-user" th:value="${iter.getLink()}"
                                                       th:id="'link_' + ${iterStat.index}">
                                            </div>
                                        </form>

                                    <td><span class="h5 m-0 text-dark" th:text="${iter.getPass()}"></span></td>
                                    <td>
                                        <a title="复制" href="javascript:void(0);"
                                           th:onclick="copy_link([[${iterStat.index}]]);" class="btn btn-success btn-circle">
                                            <i class="fas fa-copy"></i>
                                        </a>
                                        <a title="取消分享" href="javascript:void(0);" data-toggle="modal" data-target="#deleteModal"
                                           th:onclick="Values([[${iter.getUuid()}]],[[${iterStat.index}]]);" class="btn btn-danger btn-circle">
                                            <i class="fas fa-trash"></i>
                                        </a>
                                    </td>
                                    <td><span class="h5 m-0 text-dark" th:text="${iter.formatExpire()}"></span></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <!-- End of Main Content -->
        <!-- Footer -->
        <footer class="sticky-footer bg-white">
            <div class="container my-auto">
                <div class="copyright text-center my-auto">
                    <span>Copyright &copy; <a href="http://www.vfdxvffd.cn">vfdxvffd.cn</a> 2021</span>
                </div>
            </div>
        </footer>
        <!-- End of Footer -->

    </div>
</div>

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="logoutModalLabel">退出登陆？</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">选择“退出”即可退出当前帐号</div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
                <a class="btn btn-primary" href="/logout">退出</a>
            </div>
        </div>
    </div>
</div>
<!-- info Modal-->
<div class="modal fade" id="tipModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">In Plan</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <!--Select "Logout" below if you are ready to end your current session.-->
            <div class="modal-body">此功能正在加紧开发中...</div>
            <div class="modal-footer">
                <!--<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>-->
                <button class="btn btn-primary" type="button" data-dismiss="modal">确认</button>
                <!--<a class="btn btn-primary" href="login.html">Logout</a>-->
            </div>
        </div>
    </div>
</div>

<!--delete file modal-->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteModalLabel">取消分享？</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">选择“确认”以取消此文件的分享链接</div>
            <input type="hidden" id="deleteUUID" name="deleteUUID">
            <input type="hidden" id="deleteIndex" name="deleteIndex">
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
                <a class="btn btn-danger" href="javascript:void(0);" onclick="delete_share(document.getElementById('deleteUUID').value,
                                                                        document.getElementById('deleteIndex').value)">确认</a>
            </div>
        </div>
    </div>
</div>

<!--删除所有的分享-->
<div class="modal fade" id="deleteAllModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteAllModalLabel">取消所有？</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">选择“确认”取消所有文件的分享链接</div>

            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
                <a class="btn btn-danger" href="javascript:void(0);" onclick="delete_all_share()">确认</a>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/asserts/vendor/jquery/jquery.min.js}"></script>
<script th:src="@{/asserts/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>

<!-- Core plugin JavaScript-->
<script th:src="@{/asserts/vendor/jquery-easing/jquery.easing.min.js}"></script>

<!-- Custom scripts for all pages-->
<script th:src="@{/asserts/js/sb-admin-2.min.js}"></script>

<!-- Page level plugins -->
<script th:src="@{/asserts/vendor/chart.js/Chart.min.js}"></script>

<!-- Page level custom scripts -->
<script th:src="@{/asserts/js/demo/chart-area-demo.js}"></script>
<script th:src="@{/asserts/js/demo/chart-pie-demo.js}"></script>

</body>

<script type="text/javascript">

    function copy_link(index) {
        document.getElementById('link_'+index).select();
        document.execCommand("copy");
        alert('复制成功！');
    }

    function Values(uuid, index) {
        $('#deleteUUID').val(uuid);
        $('#deleteIndex').val(index);
    }

    function delete_share(uuid, index) {
        $('#deleteModal').modal('hide');
        $.ajax({
            type: "GET",
            url: "/deleteShare",
            async: false,        //异步下载
            contentType: "application/json; charset=utf-8",
            dataType: "text",
            data: {uuid: uuid},
            success: function (result) {
                if (result === "success") {
                    document.getElementById('tr'+index).style.display="none";
                } else {
                    alert('删除失败，请稍后重试！');
                }
                return false;
            },
            error: function (msg) {
                alert("发生错误");
                return false;
            }
        });
    }

    function delete_all_share() {
        $('#deleteAllModal').modal('hide');
        $.ajax({
            type: "GET",
            url: "/deleteAllShare",
            async: false,        //异步下载
            contentType: "application/json; charset=utf-8",
            dataType: "text",
            data: {},
            success: function (result) {
                if (result === "success") {
                    document.getElementById('dir_tbody').style.display="none";
                } else {
                    alert('删除失败，请稍后重试！');
                }
                return false;
            },
            error: function (msg) {
                alert("发生错误");
                return false;
            }
        });
    }

</script>

</html>